package com.lws.framework.module.usercenter.dao;

import org.hibernate.LockMode;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.lws.framework.dao.HibernateBaseDAO;
import com.lws.framework.module.usercenter.bean.User;

@Repository
public class UserDao extends HibernateBaseDAO<User> {

    public User findByUsername(String username) {
        String hql = "FROM User WHERE username = ?";
        Query query = getSession().createQuery(hql);

        query.setString(0, username)//
        .setCacheable(true);

        User user = (User) query.uniqueResult();
        return user;
    }

    public User lock(Long id) {
        User user = (User) getSession().get(User.class, id, LockMode.UPGRADE);
        return user;
    }

}
